//
//  DetailPhotoController.m
//  MPFindPart
//
//  Created by xalo on 16/5/3.
//  Copyright © 2016年 马鹏. All rights reserved.
//

#import "DetailPhotoController.h"

@interface DetailPhotoController ()

@property (strong,nonatomic)UIScrollView *scrollView;

@end

@implementation DetailPhotoController

- (void)viewWillAppear:(BOOL)animated{
    
    //设置当前所处的位置
    [self.scrollView setContentOffset:CGPointMake(kWidth *self.indexPath.row, 0)animated:NO];
    //创建滚动视图
    [self createScrollView];
    
}
- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor cyanColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
 
}
//创建滚动视图
- (void)createScrollView{
    
    for (int i = 0; i < self.receiveImageArray.count; i++) {
        
        NSDictionary *dic = self.receiveImageArray[i];
        NSURL *imageStr = dic[@"imageStr"];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(kWidth * i, 0, kWidth, kHeight)];
        [imageView sd_setImageWithURL:imageStr];
        
        [self.scrollView addSubview:imageView];
    }
    
    [self.view addSubview:self.scrollView];
}

//将字符串转换成UIImage
-(UIImage *)makeStringToImage:(NSString *)string{
    //将字符串转换为data类型
    NSData *strData = [[NSData alloc]initWithBase64EncodedString:string options:NSDataBase64DecodingIgnoreUnknownCharacters];
    //将data转换为图片
    UIImage *image = [UIImage imageWithData:strData];
    return image;
}

#pragma mark -------------懒加载
- (UIScrollView *)scrollView{
    
    if (!_scrollView) {
        
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, kWidth, kHeight - 64)];
        _scrollView.contentSize = CGSizeMake(kWidth * self.receiveImageArray.count, kHeight-64);
        _scrollView.scrollEnabled = YES;
        _scrollView.pagingEnabled = YES;
        _scrollView.bounces = NO;
        _scrollView.showsVerticalScrollIndicator = YES;
        _scrollView.showsHorizontalScrollIndicator = YES;
        
    }
    return _scrollView;
}
@end
